package com.ruoyi.project.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysRecord;
import com.ruoyi.project.system.service.ISysRecordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 出入库Controller
 *
 * @author orange
 * @date 2022-04-07
 */
@RestController
@RequestMapping("/system/record")
public class SysRecordController extends BaseController
{
    @Autowired
    private ISysRecordService sysRecordService;

    /**
     * 查询出入库列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRecord sysRecord)
    {
        startPage();
        List<SysRecord> list = sysRecordService.selectSysRecordList(sysRecord);
        return getDataTable(list);
    }

    /**
     * 导出出入库列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "出入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysRecord sysRecord)
    {
        List<SysRecord> list = sysRecordService.selectSysRecordList(sysRecord);
        ExcelUtil<SysRecord> util = new ExcelUtil<SysRecord>(SysRecord.class);
        util.exportExcel(response, list, "出入库数据");
    }

    /**
     * 获取出入库详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return AjaxResult.success(sysRecordService.selectSysRecordByRecordId(recordId));
    }

    /**
     * 新增出入库
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "出入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysRecord sysRecord)
    {
        return toAjax(sysRecordService.insertSysRecord(sysRecord));
    }

    /**
     * 修改出入库
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "出入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysRecord sysRecord)
    {
        return toAjax(sysRecordService.updateSysRecord(sysRecord));
    }

    /**
     * 删除出入库
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "出入库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(sysRecordService.deleteSysRecordByRecordIds(recordIds));
    }
}
